<?php

/**
 * 商标管理系统 v1.0.1
 *
 * 商业运营到ubtm.cn官网进行授权使用。
 *
 * (c) cighsen02 <xiayu@959602.com>
 *
 * Create at：2025.05.01
*/

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\Role\User as ServiceRoleUser;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controllers\HasMiddleware;
use Illuminate\Routing\Controllers\Middleware;

/**
 * 权限管理
 */
class RoleController extends Controller implements HasMiddleware
{
    /**
     * 权限中间件
     *
     * @return array
     */
    public static function middleware(): array
    {
         return [
            'auth:admin',
            new Middleware('permission:role-list|role-create|role-edit|role-delete', only: ['index','show']),
            new Middleware('permission:role-create', only: ['store']),
            new Middleware('permission:role-edit', only: ['update']),
            new Middleware('permission:role-delete', only: ['destroy'])
        ];
    }

    /**
     * 角色列表
     *
     * @param Request $request
     * @param ServiceRoleUser $role
     * @return JsonResponse
     */
    public function index(Request $request, ServiceRoleUser $role): JsonResponse
    {
        $page = $request->input('page', 1);

        return $this->sendResponse($role->list($page), 'success');
    }
}
